package com.sun.showcase.controller.mall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.showcase.biz.mall.service.CommentService;
import com.sun.showcase.client.domain.mall.Comment;
import com.sun.showcase.client.query.mall.CommentQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.utils.LoginContextHolder;
import com.sun.showcase.utils.StringConstant;

@Controller
@RequestMapping(value="/mall/comment") 
public class CommentController{
	
	@Autowired
	private CommentService commentService;
	
	private Result result = new Result();
	/**
	 * 跳转到Comment管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goComment")
	public String goComment(ModelMap map) {
		map.put("shopId", LoginContextHolder.get().getShopId());
		map.put("shopName", LoginContextHolder.get().getShopName());
		return "mall/comment";
	}
	/**
	 * 跳转到Comment新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleComment")
	public String handleComment(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/comment_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Comment showDesc(CommentQuery commentQuery) {
		return commentService.get(commentQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(CommentQuery commentQuery) {
		return commentService.datagrid(commentQuery);
	}
	

	/**
	 * 添加一个Comment
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(CommentQuery commentQuery) {
		commentService.add(commentQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Comment
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(CommentQuery commentQuery) {
		commentService.update(commentQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Comment
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(CommentQuery commentQuery) {
		commentService.delete(commentQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Comment
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(CommentQuery commentQuery) {
		commentService.deletePt(commentQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Comment
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(CommentQuery commentQuery) {
		List<CommentQuery> list = commentService.listAll(commentQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
	
	/**
	 * 全部数据Comment
	 */
	@ResponseBody
	@RequestMapping(value="updateStatus")
	public Result updateStatus(CommentQuery commentQuery) {
		CommentQuery update = new CommentQuery();
		update.setShowStatus(commentQuery.getShowStatus());
		update.getSearchMap().put(StringConstant.ID, commentQuery.getId());
		commentService.updatePart(update);
		result.setSuccess(true);
		result.setMsg("成功！");
		return result;
	}
	
}
